﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Character.Jarily
{
    public enum Meterial
    {
        iron, wind, fire
    }
    public enum Attribute
    {
        electricity, fire, wind
    }
    public class Chain : MonoBehaviour
    {
        [SerializeField]
        public Meterial m_meterial;
        public List<Transform> Point;
        public LinkedList<Transform> NPoint;
        public Transform[] m_point;
        private void OnEnable()
        {
            m_point = Point.ToArray();
        }
        private void OnTriggerEnter2D(Collider2D collision)
        {
            Debug.Log("Enter");
        }
        private void OnTriggerStay2D(Collider2D collision)
        { 
            switch (collision.GetComponent<SKill>().m_skillType)
            {
                case Attribute.electricity:
                    if (m_meterial == Meterial.iron) ReusableCode.electricity(m_point,Ring);
                    Debug.Log("OK");
                    break;
                case Attribute.fire:
                    //...
                    break;
                case Attribute.wind:
                    //...
                    break;
                default:
                    break;
            }
        }
        [SerializeField]
        public bool Ring;
#if UNITY_EDITOR
        public bool Draw;
        private void OnDrawGizmos()
        {
            if (Draw)
            {
                int y = 0;
                for (int i = 0; i < Point.Count; i++)
                    if (Point[i - y] == null){ Point.RemoveAt(i - y); y++; }

                Handles.color = new Color(0, 1, 0, 0.5f);

                if (Point.Count > 0)
                    for (int i = 1; i <= Point.Count; i++)
                        if (i < Point.Count) Handles.DrawLine(Point[i].transform.position, Point[i - 1].transform.position);
                        else if (i == Point.Count&&Ring) Handles.DrawLine(Point[i - 1].transform.position, Point[0].transform.position);

                foreach (Transform x in Point)
                    Handles.DrawSolidDisc(x.position, Vector3.forward, 0.3f);
            }
        }
#endif
    }
}
